#include<iostream>
#include"Task.hpp"
#include"ThreadPool.hpp"
#include<unistd.h>
#include<ctime>
using namespace std;

int main()
{
    srand((unsigned long)time(nullptr) ^ getpid());
    //ThreadPool<Task> *tp = new ThreadPool<Task>();
    ThreadPool<Task> *tp = ThreadPool<Task>::GetOnceTP(5);
    tp->run();
    //cout<<"run end"<<endl;
     while(true)
     {
        //生产的过程，制作任务的时候，要花时间
        //cout<<"while begin"<<endl;
        int x = rand()%100 + 1;
        //usleep(7721);
        int y = rand()%30 + 1;
        //cout<<"Task begin"<<endl;
        Task t(x, y, [](int x, int y)->int{
            return x + y;
        });

        //cout<<"task end"<<endl;

         std::cout << "制作任务完成: " << x << "+" << y << "=?" << std::endl;
        // logMessage(DEBUG, "制作任务完成: %d+%d=?", x, y);
        // logMessage(DEBUG, "制作任务完成: %d+%d=?", x, y);
        // logMessage(DEBUG, "制作任务完成: %d+%d=?", x, y);
        // logMessage(DEBUG, "制作任务完成: %d+%d=?", x, y);

        // 推送任务到线程池中
        tp->PushTask(t);
        //cout<<"push end"<<endl;
        sleep(1);
    }
    return 0;
}